package com.fhs.trans.config;

import com.fhs.core.trans.anno.AutoTrans;
import com.fhs.core.trans.vo.VO;
import com.fhs.trans.service.AutoTransAble;
import com.fhs.trans.service.TransableRegister;
import com.fhs.trans.service.impl.AutoTransService;
import org.springframework.beans.factory.annotation.Autowired;


import java.util.List;

/**
 * @author Alen
 * @date 2021-05-17 20:10
 * @since 2021-05-17 20:10
 */
public class DefaultTransableRegister extends TransableRegister {

    private String packageNames;

    @Autowired(required = false)
    private AutoTransService autoTransService;


    @Override
    public String getPackageNames() {
        return packageNames;
    }

    @Override
    protected void regTransable(AutoTransAble autoTransAble, AutoTrans autoTransSett) {
        autoTransService.regTransable(autoTransAble,autoTransSett);
    }

    @Override
    protected void regTransable(Class<? extends VO> entity, AutoTrans autoTransSett) {

    }

    @Override
    protected void apply(List<String> namespaceList) {
        new Thread(() -> {
            Thread.currentThread().setName("refresh auto trans cache");
            for (String namespace : namespaceList) {
                autoTransService.refreshOneNamespace( namespace);
            }
        }).start();
    }

    public void setPackageNames(String packageNames) {
        this.packageNames = packageNames;
    }

    public AutoTransService getAutoTransService() {
        return autoTransService;
    }

    public void setAutoTransService(AutoTransService autoTransService) {
        this.autoTransService = autoTransService;
    }
}
